package wyh.controller.Escort;

import com.fasterxml.jackson.databind.ObjectMapper;
import wyh.pojo.Escort;
import wyh.pojo.Patient;
import wyh.service.EscortService;
import wyh.service.PatientService;
import wyh.vo.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//9666666666666666666 ok
@WebServlet("/Escort/GetEscortServiceRecordByUserId")
public class GetEscortServiceRecordByUserIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int UserId = Integer.parseInt(req.getParameter("UserId"));
        System.out.println("访问/Patient/GetEscortServiceRecordByUserId?id="+UserId+".");
        EscortService service0 = new EscortService();
        Escort pojoUser = service0.ServicegetById(UserId);

        System.out.println("访问/Patient/GetEscortServiceRecordByUserId?Patient_id="+pojoUser.getEscortId());
        PatientService service = new PatientService();
        Patient pojo = service.ServicegetById(pojoUser.getEscortId());
        Result result= new Result(200,"查询成功",pojo);

        System.out.println("返回结果："+pojo+"。");
        System.out.println(pojo);

        ObjectMapper ojmapper = new ObjectMapper();
        String json = ojmapper.writeValueAsString(result);
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(json);
    }
}
